package com.coolwen.service;

import com.coolwen.dao.CategoryMapper;
import com.coolwen.entity.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by user on 2016/7/12.
 */
@Service("categoryService")
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper ctyDao;

    @Override
    public Category load(Integer cid) {
        return ctyDao.selectByPrimaryKey(cid);
    }

    @Override
    public int delete(Integer cid) {
        return ctyDao.deleteByPrimaryKey(cid);
    }

    @Override
    public int update(Category category) {
        return ctyDao.updateByPrimaryKeySelective(category);
    }

    @Override
    public int add(Category category) {
        return ctyDao.insert(category);
    }

    @Override
    public List<Category> list(String name) {
        if (name != null && !name.equals("")) {
            name = "%" + name + "%";
        }
        return ctyDao.list(name);
    }
}
